ARG TARGETPLATFORM
FROM --platform=$TARGETPLATFORM debian:buster
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
    apt-get install -y \
        cups \
        cups-client \
        cups-bsd \
        printer-driver-cups-pdf \
        wget \
        unzip \
        bc \
        ghostscript \
        psutils \
        libusb-1.0-0 \
        dbus \
        avahi-daemon \
        usbutils \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

RUN mkdir -p /etc/cups /var/log/cups /var/run/cups /opt/brother /dev/bus/usb

WORKDIR /app

COPY linux-brprinter-installer-2.2.4-1.gz /app/
COPY default.conf /etc/cups/cupsd.conf
COPY start.sh /app/start.sh

RUN gunzip /app/linux-brprinter-installer-2.2.4-1.gz && \
    chmod +x /app/linux-brprinter-installer-2.2.4-1

RUN chmod +x /app/start.sh

EXPOSE 631

ENTRYPOINT ["/app/start.sh"]